# encoding: utf-8
__author__ = 'wwj'
import re
import sys
reload(sys)
sys.setdefaultencoding('utf8')
sys.path.append("/Users/wwj/Downloads/shangtianjun/girl/girl/dbShell")
from dbshell import dbshell
from datetime import *
class main(dbshell):
    orderItem = [
            ['name', ''],
            ["comment",""],
            ["point",""],
            ["url",""],
            ["imgList",""],
            ["height",""],
            ["birthday",""],
            ["blood",""],
            ["questions",""],
            ["constellation",""],
            ["movieList",""],
            ["sid",""],
            ["lineId",""],
            ["email",""],
            ["phone",""],
            ["storeUrl",""],
            ["instagram",""],
            ["blog",""],
    ]
    mongoTable = "man"
    mysqlTable = "host2_man"
    # urlpoolkey = "exist"
    def __init__(self,spidername):
        super(main,self).__init__(spidername)
        import ipdb;ipdb.set_trace()
        if self.redisconn.exists("sids"):
            tmp = self.getdb("select id,url from host2_store")
            self.redisconn.expire("sids",timedelta(days=1))
            self.redisconn.hmset("sids",{x["url"]:x["id"] for x in tmp})
        # import ipdb;ipdb.set_trace()
        # self.mongofrom = self.mongo.find(self.where)


    def clean(self,y):
        if y.get("url"):
            y["url"] = y.get("url").replace("http://www.host2.jp","")
        id = self.redisconn.hget("sids",y["storeUrl"].replace("http://www.host2.jp",""))
        self.data["sid"] = id
        self.data.update(y)
        self.data["height"] = self.data["height"].replace("cm","").replace("?","")
        self.data["constellation"] = self.data["constellation"].replace("座","").replace("?","")
        if self.data.get("storeUrl"):
            self.data["storeUrl"] = self.data.get("storeUrl").replace("http://www.host2.jp","")
        if self.data.get("mail"):
            self.data["email"] = self.data["mail"]
            del self.data["mail"]
        if self.data.get("imgList"):
            self.data["imgList"] = ",".join(self.data.get("imgList"))
        else:
            self.data["imgList"] = ""
        if self.data.get("movieList"):
            self.data["movieList"] = ",".join(self.data.get("movieList"))
        else:
            self.data["movieList"] = ""
        self.data["questions"] = ",".join(self.data["questions"])


if __name__ == '__main__':
    obj = main("host2")
    obj()
